package fr.umlv.m2.uwp2011.persistence.matiere;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name="TRONC_COMMUN")
public class TroncCommun implements Serializable {
	private final static String columnType="INTEGER UNSIGNED";
	
	
	@Id
	@GeneratedValue
	@Column(name="TRONC_COMMUN_ID")
	private Long id;
	
	@Column(name="TRONC_COMMUN_LIBELLE")
	private String libelle;
	
	@ManyToMany(cascade = CascadeType.REFRESH)
		    @JoinTable(name="TRONC_COMMUN_MATIERE",
		            joinColumns={@JoinColumn(name="TRONC_COMMUN_ID", columnDefinition=columnType, nullable=false)},
		            inverseJoinColumns={@JoinColumn(name="MATIERE_ID", columnDefinition=columnType, nullable=false)})
	private List<Matiere> listMatiere;
	
	@ManyToMany(mappedBy="listTroncCommun")
	private List<Cursus> listCursus;

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public Long getId() {
		return id;
	}

	public void setListMatiere(List<Matiere> listMatiere) {
		this.listMatiere = listMatiere;
	}
	
	public Iterator<Cursus> iteratorCursus() {
		return listCursus.iterator();
	}

	public void setListCursus(List<Cursus> listCursus) {
		this.listCursus = listCursus;
	}

	public Iterator<Matiere> iteratorMatiere() {
		return listMatiere.iterator();
	}
}
